package com.ajmd.onlineexam.mapper;

import com.ajmd.onlineexam.entity.ExamPO;
import com.ajmd.onlineexam.vo.ExamVO;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.apache.commons.lang3.ObjectUtils;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * @author ajmd
 * @since 2023/5/3 16:12
 */
public interface ExamMapper extends BaseMapper<ExamPO> {
    /**
     * 查询某考生的考试列表，并显示该场考试开考次数
     * @param page
     * @param account
     * @param searchValue
     * @return
     */
    @Select("<script>"+
            " SELECT a.*,IFNULL(b.count, 0) as participationTimes FROM e_exam a left join "+
            " (select exam_id, COUNT(*) as count from e_person_exam  where student_id=#{account} and status!=0 and status!=1 group by exam_id ) as b "+
            " on a.id = b.exam_id "+
            " <if test='searchValue != null and searchValue.trim().length() > 0'>" +
            " WHERE a.exam_name LIKE CONCAT('%', #{searchValue}, '%') "+
            " </if>"+
            "</script>")
    IPage<ExamVO> studentSelectExams(Page<ExamVO > page,String account,String searchValue);
}
